#include <gtest/gtest.h>
#include "common.h"

using namespace ::std;

class Solution {
public:
    int countSubstrings(string s);
};

// 暴力解
// 遍历所有元素,每遍历到一个元素，都以他为支点，求出所有到目前为止，包含该元素的所有回文子串
int Solution::countSubstrings(string s) {
    int size = s.size(), result = 0;
    for(int i = 0; i < size; ++i) {
        for(int j = i; j >= 0; --j) {
            int m, n;
            for(m = i, n = j; m >= n && s[m] == s[n]; --m, ++n) ;
            if(m < n) result++;
        }
    }
    return result;
}

class CountSubstringsCheck : public ::testing::Test {
public:
	class Solution solution;
};

TEST_F(CountSubstringsCheck, testCountSubstrings_1) {
    string s = "abc";
    EXPECT_TRUE(3 == solution.countSubstrings(s));
}

TEST_F(CountSubstringsCheck, testCountSubstrings_2) {
    string s = "aaa";
    EXPECT_TRUE(6 == solution.countSubstrings(s));
}

TEST_F(CountSubstringsCheck, testCountSubstrings_3) {
    string s = "aksjhdfkjsdhkwersfddsfsdfsdfsdfdssdgdfsfsdfhsdfsfgsabc";
    EXPECT_TRUE(65 == solution.countSubstrings(s));
}

int main() {
	::testing::InitGoogleTest();
	return RUN_ALL_TESTS();
}
